package com.hc.programming.array;

import java.util.Scanner;

/**
 * @author huangchao E-mail:fengquan8866@163.com
 * @version 创建时间：2024/6/24 21:37
 */
public class 最高分是多少 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = 0, m = 0;
        int[] arr = null;
        while (in.hasNextLine()) {
            String str = in.nextLine();
            if (n == 0) {
                String[] s = str.split(" ");
                n = Integer.parseInt(s[0]);
                m = Integer.parseInt(s[1]);
                continue;
            }
            if (arr == null) {
                arr = new int[n];
                String[] s = str.split(" ");
                for (int i = 0; i < n; i++) {
                    arr[i] = Integer.parseInt(s[i]);
                }
                continue;
            }
            if (str.charAt(0) == 'Q') {
                String[] s = str.substring(2).split(" ");
                int a = Integer.parseInt(s[0]);
                int b = Integer.parseInt(s[1]);
                if (a > b) {
                    int t = a;
                    a = b;
                    b = t;
                }
                int max = 0;
                for (int i = a; i <= b; i++) {
                    if (arr[i - 1] > max) {
                        max = arr[i - 1];
                    }
                }
                System.out.println(max);
            } else if (str.charAt(0) == 'U') {
                String[] s = str.substring(2).split(" ");
                int a = Integer.parseInt(s[0]);
                int b = Integer.parseInt(s[1]);
                arr[a - 1] = b;
            }
            m--;
            if (m == 0) {
                n = 0;
                arr = null;
            }
        }
    }
}
